package arrAndstr;

/*
    189. 轮转数组
*/
public class T189 {

    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,4,5,6,7};
        int k = 3;

        rotate(array, k);

        for (int i : array) {
            System.out.print(i + " ");
        }
    }

    public static void rotate(int[] nums, int k) {
        int len = nums.length;
        k = k%len;
        int[] newArray = new int[len];
        copyArray(nums, newArray);

        for(int i=0; i<len; i++) {
            int afterIndex = (i+k)%len;
            nums[afterIndex] = newArray[i];
        }
    }

    public static void copyArray(int[] nums, int[] newArray) {
        for(int i=0; i<nums.length; i++) {
            newArray[i] = nums[i];
        }
    }
}
